<?php

namespace Admin\Controller;

class DriverTxController extends AdminController {

    public function index() {

        $is_export = I("is_export", 0, 'intval');
        $where .= '1=1 ';

        $keywords = I('keywords');
        if ($keywords) {
            $where .= " and (d.driver_name like '%" . $keywords . "%' or d.driver_phone like '%" . $keywords . "%')";
            $this->assign('keywords', $keywords);
        }


        //日期选择
        $start_date = I("start_date");
        $end_date = I("end_date");


        if (!empty($end_date) && !empty($start_date)) {
            if ($end_date <= $start_date) {
                $this->error('开始时间不允许小于等于结束时间');
                exit;
            } else {
                $where .= " and dt.create_time between '$start_date 00:00:00' AND " . "'" . $end_date . ' 23:59:59' . "'";
//                $where['sp.create_time'] = array("between", array($start_date, $end_date . ' 23:59:59'));
            }
            $this->assign("start_date", $start_date);
            $this->assign("end_date", $end_date);
        } else {
            if (!empty($start_date)) {
//                $where['sp.create_time'] = array('EGT', $start_date);
                $where .= " and dt.create_time >= '$start_date 00:00:00'";
                $this->assign("start_date", $start_date);
            }

            if (!empty($end_date)) {
//                $where['sp.create_time'] = array('ELT', $end_date . ' 23:59:59');
                $where .= ' and dt.create_time <=' . "'" . $end_date . '23:59:59' . "'";
                $this->assign("end_date", $end_date);
            }
        }


        $M = M()->table("ot_driver_tx dt")
                ->join('ot_driver d on dt.driver_id = d.driver_id')
                ->join('ot_fleet f on d.fleet_id = f.fleet_id');


        if ($is_export) {
            $exportList = $M->field('dt.tx_id,'
                            . 'd.driver_name,'
                            . 'f.fleet_name,'
                            . 'CONCAT(d.driver_phone," ") as d.driver_phone,'
                            . 'dt.tx_price,'
                            . 'dt.create_time')->where($where)->select();


            exportExcel('司机提现记录导出', array('ID', '司机姓名', '所属车队', '手机号', '提现金额', '提现时间'), $exportList);
        }
        $field = 'dt.*,d.driver_name,d.driver_phone,f.fleet_name';

        $order = "dt.tx_id desc";
        $list = $this->lists($M, $where, $order, $field);

        $this->assign('_list', $list);
        $this->display();
    }

}
